home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Sep
/
di9809cd
/
TVDEMO1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-12-12
|
6KB
|
233 lines
unit TVDEMO1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, TelevisionLIB, SharedMemory;
type
TTelevisionDemo = class(TForm)
TVOffImage: TImage;
TVOnImage: TImage;
Panel1: TPanel;
PowerBtn: TButton;
ChBtn1: TButton;
ChBtn2: TButton;
ChBtn3: TButton;
ChBtn4: TButton;
ChBtn5: TButton;
ChBtn6: TButton;
ChBtn7: TButton;
ChBtn8: TButton;
ChBtn9: TButton;
ChBtn0: TButton;
SleepBtn: TButton;
CCBtn: TButton;
ChannelLbl: TLabel;
SleepLbl: TLabel;
TVTimer: TTimer;
TileMap: TImage;
CCLbl: TLabel;
procedure FormCreate(Sender: TObject);
procedure PowerBtnClick(Sender: TObject);
procedure TVTimerTimer(Sender: TObject);
procedure SleepBtnClick(Sender: TObject);
procedure ChBtn0Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure CCBtnClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
SharedMemory : PTELEVISION_SMEM;
SharedMem : TSharedMem;
procedure UpdateText;
procedure TileBackground;
public
{ Public declarations }
Tile : TBitmap;
TVPower : Boolean;
TVCC : Boolean;
TVChannel : Integer;
BuildChannel : string;
TVCCWords : Integer;
TVSleepTimer : LongInt;
TVSleepActive : Boolean;
TVElaspedTime : LongInt;
TVBaseTime : LongInt;
end;
var
TelevisionDemo: TTelevisionDemo;
implementation
{$R *.DFM}
//
// Utility function(s)
//
procedure TTelevisionDemo.TileBackground;
var num_across, num_down, yoff, xoff, y_coord, x_coord, y, x : integer;
begin
//tiling logic based upon code by Casey Charlton
num_across := (Width div Tile.Width) + 1;
num_down := (Height div Tile.Height) +1;
xoff := (Width - ((num_across + 1) * Tile.Width)) div 2;
yoff := (Height - ((num_down + 1) * Tile.Height)) div 2;
for x := 0 to num_across do
for y := 0 to num_down do
begin
x_coord := (x * Tile.Width) + xoff;
y_coord := (y * Tile.Height) + yoff;
Canvas.Draw(x_coord, y_coord, Tile);
end;
end;
//
// Form/System event-related procedures
//
procedure TTelevisionDemo.FormCreate(Sender: TObject);
begin
SharedMem:=nil;
Tile:=TBitmap.Create;
Tile.Assign(TileMap.Picture);
SleepLbl.Caption:='';
ChannelLbl.Caption:='';
CCLbl.Caption:='';
TVPower:=False;
TVOffImage.Visible:=True;
TVOnImage.Visible:=False;
TVCC:=False;
TVChannel:=1;
BuildChannel:='';
TVCCWords:=0;
TVSleepTimer:=0;
TVBaseTime:=0;
TVSleepActive:=False;
TVElaspedTime:=0;
//create shared memory communications
SharedMem:=TSharedMem.Create('Television_SMEM',SizeOf(TTELEVISION_SMEM));
SharedMemory:=SharedMem.Buffer;
end;
procedure TTelevisionDemo.FormPaint(Sender: TObject);
begin
TileBackground;
end;
procedure TTelevisionDemo.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//shutdown shared memory communications
SharedMem.Free;
end;
//
// Master timing mechanism to update shared memory and process
// internal timing counters
//
procedure TTelevisionDemo.TVTimerTimer(Sender: TObject);
begin
if TVPower then
begin
if TVBaseTime<>0 then TVElaspedTime:=Round((GetTickCount-TVBaseTime)/1000);
if TVSleepActive then Dec(TVSleepTimer);
if TVCC then Inc(TVCCWords,Round(Random(30)));
end;
UpdateText;
if (SharedMem<>nil) then
begin
if TVPower then SharedMemory^.Power:=1 else SharedMemory^.Power:=0;
SharedMemory^.Channel:=TVChannel;
if TVCC then
SharedMemory^.ClosedCaptioningEnabled:=1
else
SharedMemory^.ClosedCaptioningEnabled:=0;
SharedMemory^.SleepTimer:=TVSleepTimer;
SharedMemory^.TimeOn:=TVElaspedTime;
SharedMemory^.ClosedCaptioningWordsPerSecond:=TVCCWords;
end;
end;
//
// Handle screen updates
//
procedure TTelevisionDemo.UpdateText;
begin
if TVPower then
begin
if (TVSleepTimer=0) then
if TVSleepActive then
begin
TVPower:=False;
SleepLbl.Caption:='';
ChannelLbl.Caption:='';
CCLbl.Caption:='';
TVOnImage.Visible:=False;
TVOffImage.Visible:=True;
end else
SleepLbl.Caption:=''
else
SleepLbl.Caption:='Sleep ('+IntToStr(TVSleepTimer)+')';
if TVChannel<10 then
ChannelLbl.Caption:='C0'+IntToStr(TVChannel)
else
ChannelLbl.Caption:='C'+IntToStr(TVChannel);
if TVCC then
CCLbl.Caption:='CC On'
else
CCLbl.Caption:='';
end else
begin
SleepLbl.Caption:='';
ChannelLbl.Caption:='';
CCLbl.Caption:='';
end;
end;
//
// User control-related event handlers
//
procedure TTelevisionDemo.PowerBtnClick(Sender: TObject);
begin
TVPower:=not TVPower;
TVOnImage.Visible:=Not TVOnImage.Visible;
TVOffImage.Visible:=Not TVOffImage.Visible;
TVCCWords:=0;
TVSleepTimer:=0;
TVElaspedTime:=0;
TVBaseTime:=GetTickCount;
TVSleepActive:=False;
UpdateText;
end;
procedure TTelevisionDemo.SleepBtnClick(Sender: TObject);
begin
TVSleepActive:=not TVSleepActive;
if TVSleepActive then TVSleepTimer:=60 else TVSleepTimer:=0;
UpdateText;
end;
procedure TTelevisionDemo.ChBtn0Click(Sender: TObject);
begin
if not TVPower then Exit;
if BuildChannel='' then
BuildChannel:=Trim(TButton(Sender).Caption)
else
begin
BuildChannel:=BuildChannel+Trim(TButton(Sender).Caption);
TVChannel:=StrToInt(BuildChannel);
BuildChannel:='';
UpdateText;
end;
end;
procedure TTelevisionDemo.CCBtnClick(Sender: TObject);
begin
TVCC:=not TVCC;
TVCCWords:=0;
UpdateText;
end;
end.